package com.yanqu.road.logic.activity.foxcard.game.sorcery;

import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.logic.activity.foxcard.FoxCardConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.utils.RandomHelper;

import java.util.List;

/**
 * 随机摧毁{0}张扑克牌，并随机添加{1}张带有【增强效果】的人头牌加入手牌。
 * 毁牌数量|增加牌数量|牌点数下限|牌点数上限|buffSort
 */
public class FoxCardSorceryUse3 extends FoxCardSorceryUseBase {
    @Override
    protected boolean sorceryUse(FoxCardGameLogic gameLogic) {
        int num = sorceryConfig.getParamList().get(0);
        int addCardNum = sorceryConfig.getParamList().get(1);
        int minPoint = sorceryConfig.getParamList().get(2);
        int maxPoint = sorceryConfig.getParamList().get(3);
        int buffSort = sorceryConfig.getParamList().get(4);

        if (num <= 0 || addCardNum <= 0) {
            return false;
        }

        if (gameLogic.getGameData().getHandCards().isEmpty()) {
            return false;
        }

        List<FoxHandCard> randomList = RandomHelper.getRandomList(gameLogic.getGameData().getHandCards(), num);
        gameLogic.destroyHandCards(randomList);

        FoxCardConfig config = gameLogic.getConfig();
        for (int i = 0; i < addCardNum; i++) {
            int randomPoint = config.getRandomHelper().next(minPoint, maxPoint + 1);
            int randomColor = config.getRandomHelper().next(1, FoxCardGameLogic.CARD_COLOR_NUM + 1);
            int reinforceEffect = 0;
            int versionEffect = 0;
            int sealEffect = 0;

            int buffId = config.randomBuffId(buffSort);

            if (buffSort == 1) {
                reinforceEffect = buffId;
            } else if (buffSort == 2) {
                versionEffect = buffId;
            } else if (buffSort == 3) {
                sealEffect = buffId;
            }

            gameLogic.addNewHandCard(randomPoint, randomColor, reinforceEffect, versionEffect, sealEffect);
        }


        return true;
    }
}
